<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <style>
        body {
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f5f5f5;
        }
        .login-box {
            background-color: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            width: 300px;
            text-align: center;
        }
        h2 {
            color: #ff6b81;
            margin-top: 0;
        }
        .form-group {
            margin-bottom: 20px;
            text-align: left;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            background-color: #ff6b81;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
            font-size: 16px;
        }
        button:hover {
            background-color: #ff5777;
        }
        .success {
            color: #4CAF50;
            font-weight: bold;
            margin: 20px 0;
            display: none;
        }
        .ok-btn {
            background-color: #4CAF50;
            display: none;
            margin-top: 15px;
        }
        .register-link {
            margin-top: 15px;
            display: block;
            text-align: center;
        }
        .register-link a {
            color: #666;
            text-decoration: none;
        }
        .register-link a:hover {
            color: #ff6b81;
            text-decoration: underline;
        }
        /* 新增错误提示样式 */
        .error-message {
            color: #ff6b81;
            font-size: 12px;
            margin-top: 5px;
            display: none;
        }
        .error-input {
            border-color: #ff6b81 !important;
        }
    </style>
</head>
<body>
    <div class="login-box">
        <h2>用户登录</h2>
        <div class="form-group">
            <label for="username">账号</label>
            <input type="text" id="username" placeholder="请输入数字账号">
            <div class="error-message" id="username-error">账号只能由数字构成</div>
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" placeholder="请输入密码">
        </div>
        <button id="login-btn">登录</button>
        
        <div class="register-link">
            <a href="注册.html">没有账号，前往注册</a>
        </div>
        
        <div class="success" id="success-message">登录成功</div>
        <button class="ok-btn" id="ok-btn">好的</button>
    </div>

    <script>
        // 获取DOM元素
        const usernameInput = document.getElementById('username');
        const usernameError = document.getElementById('username-error');
        const loginBtn = document.getElementById('login-btn');
        
        // 实时验证账号输入
        usernameInput.addEventListener('input', function() {
            const username = this.value;
            
            // 检查是否包含非数字字符
            if (/[^0-9]/.test(username)) {
                this.classList.add('error-input');
                usernameError.style.display = 'block';
                loginBtn.disabled = true;
                loginBtn.style.opacity = '0.6';
            } else {
                this.classList.remove('error-input');
                usernameError.style.display = 'none';
                loginBtn.disabled = false;
                loginBtn.style.opacity = '1';
            }
        });
        
        // 登录按钮点击事件
        loginBtn.addEventListener('click', function() {
            const username = usernameInput.value;
            
            // 再次验证账号格式
            if (/[^0-9]/.test(username)) {
                usernameInput.classList.add('error-input');
                usernameError.style.display = 'block';
                return; // 阻止继续执行
            }
            
            // 验证通过，继续登录流程
            document.querySelectorAll('.form-group, #login-btn, .register-link').forEach(el => {
                el.style.display = 'none';
            });
            
            document.getElementById('success-message').style.display = 'block';
            document.getElementById('ok-btn').style.display = 'block';
        });
        
        document.getElementById('ok-btn').addEventListener('click', function() {
            window.location.href = "主页(已登录).html";
        });
    </script>
</body>
</html>